using TMPro;
using UnityEngine.UI;

public static class TextExtension
{
	public static void SetNumberText(this Text myText, float value, bool needDollar = false)
	{
		if (value > 1000f)
		{
			if (value % 1000f > 0f)
			{
				myText.text = (value / 1000f).ToString("0.0") + "k" + (needDollar ? "$" : "");
			}
			else
			{
				myText.text = (value / 1000f).ToString("0") + "k" + (needDollar ? "$" : "");
			}
		}
		else
		{
			myText.text = value + (needDollar ? "$" : "");
		}
	}

	public static void SetNumberTextMesh(this TextMeshPro myText, int value, bool needDollar = false)
	{
		if (value > 1000)
		{
			if (value % 1000 > 0)
			{
				myText.text = ((float)value / 1000f).ToString("0.0") + "k" + (needDollar ? "$" : "");
			}
			else
			{
				myText.text = ((float)value / 1000f).ToString("0") + "k" + (needDollar ? "$" : "");
			}
		}
		else
		{
			myText.text = value + (needDollar ? "$" : "");
		}
	}

	public static void SetNumberTextMeshUGUI(this TextMeshProUGUI myText, int value, bool needDollar = false)
	{
		if (value > 1000)
		{
			if (value % 1000 > 0)
			{
				myText.text = ((float)value / 1000f).ToString("0.0") + "k" + (needDollar ? "$" : "");
			}
			else
			{
				myText.text = ((float)value / 1000f).ToString("0") + "k" + (needDollar ? "$" : "");
			}
		}
		else
		{
			myText.text = value + (needDollar ? "$" : "");
		}
	}

	public static string TextNumber(int value)
	{
		if (value > 1000)
		{
			if (value % 1000 > 0)
			{
				return ((float)value / 1000f).ToString("0.0") + "k";
			}
			return ((float)value / 1000f).ToString("0") + "k";
		}
		return value.ToString();
	}
}
